package com.pingbu.tijian.hospital.backapi.api;

import com.github.pagehelper.PageInfo;
import com.pingbu.common.bean.ResultBean;
import com.pingbu.tijian.hospital.backapi.bean.entity.*;
import com.pingbu.tijian.hospital.backapi.service.BuzhiZuoyeService;
import com.pingbu.tijian.hospital.backapi.service.ClassesService;
import com.pingbu.tijian.hospital.backapi.service.JoinClassMessageService;
import com.pingbu.tijian.hospital.backapi.service.UserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/classes") //getUserInfoJoinClassMessageByClassesId
public class ClassesController {

    private static Logger logger = LoggerFactory.getLogger(ClassesController.class);

    @Autowired
    private ClassesService classesService;

    @Autowired
    private JoinClassMessageService joinClassMessageService;

    @PostMapping("/save")
    public ResultBean<Classes> add(@RequestBody Classes param) {
        ResultBean<Classes> rb1 = null;
        if(param.getNoid()!=null){
            rb1 = classesService.edit(param);
        }else{
            rb1 = classesService.add(param);
        }
        return rb1;
    }

    @PostMapping("/page")
    public ResultBean<PageInfo<Classes>> page(@RequestBody Classes param) {
        ResultBean<PageInfo<Classes>> rb1 = classesService.page(param);
        return rb1;
    }

    @PostMapping("/list")
    public ResultBean<List<Classes>> list(@RequestBody UserInfo param) {
        ResultBean<List<Classes>> rb1 = classesService.list(param);
        return rb1;
    }

    @PostMapping("/searchClasses")
    public ResultBean<Classes> searchClasses(@RequestBody Classes param) {
        return classesService.searchClasses(param);
    }

    @PostMapping("/delete")
    public ResultBean<Integer> delete(@RequestBody Classes param) {
        ResultBean<Integer> rb1 = classesService.delete(param);
        return rb1;
    }

    @PostMapping("/saveStudents")
    public ResultBean<Integer> saveStudents(@RequestBody Classes param) {
        ResultBean<Integer> rb1 = classesService.saveStudents(param);
        return rb1;
    }

    @PostMapping("/currentStudents")
    public ResultBean<List<ClassStudent>> currentStudents(@RequestBody ClassStudent param){
        ResultBean<List<ClassStudent>> rb1 = classesService.currentStudents(param);
        return rb1;
    }

    @PostMapping("/defaultClass")
    public ResultBean<Integer> defaultClass(@RequestBody UserInfo param){
        ResultBean<Integer> rb1 = classesService.defaultClass(param);
        return rb1;
    }

    @PostMapping("/getCurrentClass")
    public ResultBean<Classes> getCurrentClass(@RequestBody UserInfo param){
        ResultBean<Classes> rb1 = classesService.getCurrenClass(param);
        return rb1;
    }

    @PostMapping("/getUserInfoClasses")
    public ResultBean<Classes> getUserInfoClasses(@RequestBody UserInfo param){
        ResultBean<Classes> rb1 = classesService.getUserInfoClasses(param);
        return rb1;
    }

    /**
     * getUserInfoJoinClassMessageByClassesId 获取当前班级下用户加入班级的信息
     */
    @PostMapping("/getUserInfoJoinClassMessageByClassesId")
    public ResultBean<JoinClassMessage> getUserInfoJoinClassMessageByClassesId(@RequestBody Classes param){
          return  joinClassMessageService.getUserInfoJoinClassMessageByClassesId(param);
    }

    @PostMapping("/isUserInfoApplyJoinClass")
    public ResultBean<Integer> isUserInfoApplyJoinClass(@RequestBody JoinClassMessage joinClassMessage){
        return joinClassMessageService.isUserInfoApplyJoinClass(joinClassMessage);

    }

}
